import UnityEngine

class Txs_CharacterMotor (MonoBehaviour): 
	public instance as Txs_CharacterMotor
	
	public speed as single = 50.0F
	public rotSpeed as single = 2.0F
	public jumpSpeed as single = 8.0F
	public gravity as single = 20.0F
	
	public enableJump = false
	
	private moveDirection as Vector3 = Vector3.zero
	private controller as CharacterController
	
	private x as single = 0.0F

	def Start ():
		instance = self
		controller = gameObject.GetComponent(CharacterController)
		angles = transform.eulerAngles
		x = angles.y
	
	def Update ():
		if(Input.GetAxis("Mouse ScrollWheel") > 0):
        	speed += 2
        	if speed>=100:
        		speed = 100
    	elif(Input.GetAxis("Mouse ScrollWheel") < 0):
        	speed -= 2
        	if speed <= 0:
        		speed = 0

		horizontalInput = Input.GetAxis("Horizontal")
		verticalInput = Input.GetAxis("Vertical")
		if Input.GetMouseButton(0):
			x += Input.GetAxis("Mouse X")*rotSpeed
		
			characterRotation = Quaternion.Euler(0,x,0)
			transform.rotation = characterRotation
		
		moveDirection = Vector3(horizontalInput,0,verticalInput)
		moveDirection = transform.TransformDirection(moveDirection)
		moveDirection *= speed	
		moveDirection *= Time.deltaTime
		controller.Move(moveDirection)
		

		
		